package com.hlhj.funlike_business.activity;

import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.hlhj.funlike_business.R;
import com.hlhj.funlike_business.bean.MsgBean;
import com.hlhj.funlike_business.data.SPUser;
import com.hlhj.funlike_business.presenter.PhoneNumberPresenter;
import com.hlhj.funlike_business.views.PhoneNumberView;

import org.greenrobot.eventbus.EventBus;
import org.jetbrains.annotations.NotNull;

public class PhoneNumberAty extends BaseActivity<PhoneNumberView, PhoneNumberPresenter> implements PhoneNumberView {

    private ImageView img_back;
    private TextView tv_title, btn_ok;
    private EditText edit_phone;
    private String tel;

    @Override
    protected int getContentId() {
        return R.layout.aty_phonenum;
    }

    @Override
    protected void initData() {
        tv_title.setText("电话号码");
        tel = getIntent().getStringExtra("phoneNum");
    }

    @NotNull
    @Override
    public PhoneNumberView bindView() {
        return this;
    }

    @NotNull
    @Override
    public PhoneNumberPresenter createPresenter() {
        return new PhoneNumberPresenter();
    }

    @Override
    public void initView() {
        img_back = findViewById(R.id.img_back);
        tv_title = findViewById(R.id.tv_title);
        edit_phone = findViewById(R.id.edit_phone);
        btn_ok = findViewById(R.id.btn_ok);
    }

    @Override
    public void logicStart() {
        edit_phone.setText(tel);
    }

    @Override
    public void setListener() {
        img_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        btn_ok.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (null != edit_phone.getText().toString() || !"".equals(edit_phone.getText().toString())) {
                    getPresenter().LoadResult(PhoneNumberAty.this, edit_phone.getText().toString());
                } else {
                    Toast.makeText(PhoneNumberAty.this, "请输入电话号码", Toast.LENGTH_SHORT).show();
                }
            }
        });
    }

    @Override
    public void showResult(MsgBean msgBean) {
        new SPUser(getApplication()).setShopTel(edit_phone.getText().toString());
        Toast.makeText(this, msgBean.getMsg().toString(), Toast.LENGTH_SHORT).show();
        EventBus.getDefault().post("刷新");
        finish();
    }
}
